﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;

namespace Controllers
{
    public class IMCoopschemeController : BaseController
    {
        public ActionResult Find(int start, int limit)
        {
            string sql = @"SELECT a.Id,b.Grade,LowerQuantity,HigherQuantity,InvestorRate,GuanXiangRate,IMRate,a.OrderNo,a.Remarks
  FROM CMS_IMCoopscheme a,CMS_IMGrade b
  where a.IMGradeId=b.Id;";
            IEnumerable<IMCoopschemeDTO> list = ctx.ExecuteQuery<IMCoopschemeDTO>(sql).ToList();
            CJson CJson = new CJson();
            string json = CJson.ToJsonString("totalCount:" + list.Count() + ",data", list.Skip(start).Take(limit).ToList());
            return Content(json);
        }
        public ActionResult Delete(int id)
        {
            var rdto = new ResultMessages();
            rdto.Message = "";
            CMS_IMCoopscheme model = ctx.CMS_IMCoopscheme.Single(q => q.Id == id);
            try
            {
                ctx.CMS_IMCoopscheme.DeleteOnSubmit(model);
                ctx.SubmitChanges();
                rdto.Message = "删除成功";
                rdto.Result = true;
            }
            catch (Exception ex)
            {
                rdto.Message = "删除失败";
                rdto.Result = false;
            }
            return Json(rdto);
        }
    }
}